import VueRouter from "vue-router";
import Message from "element-ui/packages/message/src/main";


let router = new VueRouter({

    routes: [
        {path: '/', redirect: '/login'},
        {path: '/login', meta: {name: '登录'}, component: () => import('@/page/login')},
        {path: '/register', meta: {name: '注册'}, component: () => import('@/page/register')},
        {path: '/Index', meta: {name: '主治医生首页'},redirect:'Welcome',component: () => import('@/page/Index')},
        {path: '/AdminIndex', meta: {name: '管理员主页'},redirect:'/admin/Welcome',component: () => import('@/page/AdminIndex')},
        {
            // 主治医生身份页面
            path: '/Index',
            component: () => import('@/page/Index'),
            children: [
                // 客户档案管理
                {path: '/CustomerProfile', meta: {name: '客户档案管理'}, component: () => import('@/page/CustomerProfile')},
                // 客户预约管理
                {path: '/CustomerTest', meta: {name: '客户预约管理'}, component: () => import('@/page/CustomerTest')},
                // 体验信息管理
                {path: '/TestInformation', meta: {name: '体检信息管理'}, component: () => import('@/page/TestInformation')},
                // 咨询管理
                {path: '/Consult', meta: {name: '咨询管理'}, component: () => import('@/page/Consult')},
                // 回访管理
                {path: '/ReturnVisit', meta: {name: '回访管理'},  component: () => import('@/page/ReturnVisit')},
                // 客户关怀
                {path: '/CustomerCare', meta: {name: '客户关怀'},  component: () => import('@/page/CustomerCare')},
                // 知识库类型管理
                {path: '/KnowledgeVaseT', meta: {name: '知识库类型管理'}, component: () => import('@/page/KnowledgeVaseT')},
                // 知识库内容管理
                {path: '/KnowledgeContent', meta: {name: '知识库内容管理'}, component: () => import('@/page/KnowledgeContent')},
                // 欢迎界面
                {path: '/Welcome',meta:{name:'欢迎'}, component: () => import('@/page/Welcome')},
            ],
        },
        {
            // 主治主任身份页面
            path: '/AdminIndex',
            component: () => import('@/page/AdminIndex'),
            children: [
                // 知识库类型管理
                {path: '/admin/KnowledgeVaseT', meta: {name: '知识库类型管理'}, component: () => import('@/page/KnowledgeVaseT')},
                // 知识库内容管理
                {path: '/admin/KnowledgeContent', meta: {name: '知识库内容管理'}, component: () => import('@/page/KnowledgeContent')},
                // 用户管理
                {path: '/admin/UserManagement', meta: {name: '用户管理'},  component: () => import('@/page/UserManagement')},
                // 欢迎界面
                {path: '/admin/Welcome',meta:{name:'欢迎'}, component: () => import('@/page/Welcome')},
            ],
        },
    ],
    //去掉路径上的＃号
    mode:'history'
});

let notNeedLogin = ['/login','/register'];

router.beforeEach((to,from,next) => {
    if (notNeedLogin.indexOf(to.path)===-1){
        if (localStorage.getItem('TOKEN' ) == null){
            Message.warning('请登录!');
            next('/login');
        }
    }
    document.title = `私人健康诊所 - ${to.meta.name}`;
    next();
})

export default router